// dfs + 剪枝
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let m, n; //m行, n列
let initArr = [];
rl.on("line", (line)=>{
    if(m === undefined) {
        [m, n] = line.trim().split(",").map(Number)
    } else {
        initArr.push(line.trim().split(","))
        if(initArr.length === m) {
            console.log(getResult(m, n, initArr))
            //clear
            m = n = undefined
            initArr.length = 0
        }
    }

})

function getResult(m, n, initArr) {
    let count = 0
    for (let i = 0; i < m ; i++) {
        for (let j = 0; j <n ; j++) {
            if(initArr[i][j] === "M") {
                count = Math.max(getMax(i, j,m, n, initArr), count)
            }
        }
    }
    return count
}

function getMax(i, j, m, n, initArr) {
    let count = 1
    let tempCount = 1

    // 横
    if(j - 1 < 0 || initArr[i][j - 1] !== "M") {
        let l = j - 1
        let r = j + 1
        while(l >= 0) {
            if(initArr[i][l] === "M") {
                tempCount++
                l--
            } else {
                break
            }
        }
        while(r < n) {
            if(initArr[i][r] === "M") {
                tempCount++
                r++
            } else {
                break
            }
        }
        count = Math.max(tempCount, count)
    }

    //竖
    if(i - 1 < 0 || initArr[i - 1][j] !== "M"){
        tempCount = 1
        let t = i - 1
        let b = i + 1
        while(t >= 0) {
            if(initArr[t][j] === "M") {
                tempCount++
                t--
            } else {
                break
            }
        }
        while(b < m) {
            if(initArr[b][j] === "M") {
                tempCount++
                b++
            } else {
                break
            }
        }
        count = Math.max(tempCount, count)
    }

    //正斜/
    if((i - 1 < 0 || j + 1 === m ) || initArr[i - 1][j + 1] !== "M") {
        tempCount = 1
        let a = i - 1
        let b = j + 1
        while(b < n && a >= 0) {
            if(initArr[a][b] === "M") {
                tempCount++
                a--
                b++
            } else {
                break
            }
        }
        let c = i + 1
        let d = j - 1
        while(d >= 0 && c < m) {
            if(initArr[c][d] === "M") {
                tempCount++
                c++
                d--
            } else {
                break
            }
        }
        count = Math.max(tempCount, count)
    }

    // 反斜 \
    if((i - 1 < 0 || j - 1 === -1) || initArr[i - 1][j - 1] !== "M") {
        tempCount = 1
        let a = i - 1
        let b = j - 1
        while(a >= 0 && b >= 0) {
            if(initArr[a][b] === "M") {
                tempCount++
                a--
                b--
            } else {
                break
            }
        }
        let c = i + 1
        let d = j + 1
        while(c < m && d < n) {
            if(initArr[c][d] === "M") {
                tempCount++
                c++
                d++
            } else {
                break
            }
        }
        count = Math.max(tempCount, count)
    }

    return count

}